package com.liss.lissaiagent.rag;


import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.rag.Query;
import org.springframework.ai.rag.preretrieval.query.transformation.QueryTransformer;
import org.springframework.ai.rag.preretrieval.query.transformation.RewriteQueryTransformer;
import org.springframework.stereotype.Component;

/**
 * @Author: Mr.Li
 * @CreateTime: 2025-10-12
 * @Description: 查询重写
 * @Version: 1.0
 */
@Component
public class QueryWriter {

    private final ChatClient.Builder chatClientBuilder;

    private final QueryTransformer queryTransformer;

    public QueryWriter(ChatModel dashscopeChatModel) {
        this.chatClientBuilder = ChatClient.builder(dashscopeChatModel);
        queryTransformer = RewriteQueryTransformer.builder()
                .chatClientBuilder(chatClientBuilder)
                .build();
    }

    public String  queryWriter(String prompt){
        //执行查询重写
        Query transform = queryTransformer.transform(new Query(prompt));
        //输出重写后的
        return transform.text();
    }




}
